<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>健康体检</title>

    <link rel="stylesheet" href="../css/page-health-report.css" />

    <script src="../js/axios-0.18.0.js"></script>
    <script src="../js/vue.js"></script>
</head>

<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
    <div id="app">
        <!-- 页面头部 -->
        <div class="top-header">
            <span class="f-left" onclick="goBack()"><i class="icon-back"></i>返回</span>
            <span class="center">千锋健康</span>
            <span class="f-right"><i class="icon-more"></i></span>
        </div>
        <!-- 页面内容 -->
        <div class="contentBox">
            <div class="list-row3">
                <div class="report-item"  v-for="(report, idx) in reports">
                    <div class="item-name">
                        <div class="info">
                            <span class="name">{{report.name}}</span>
                            <span class="sex" v-if="report.sex == 1">男</span>
                            <span class="sex" v-if="report.sex == 2">女</span>
                        </div>
                    </div>
                    <div class="item-content">
                        <ul class="box">
                            <li>体检日期：<span>{{report.healthDate}}</span></li>
                            <li>档案号：<span>{{report.fileNumber}}</span></li>
                            <li>体检套餐：<span>{{report.setmealName}}</span></li>
                            <li>上传时间：<span>{{report.uploadTime}}</span></li>
                            <li>
                                <span>状态：{{report.orderStatus}}</span><br>
                                <span style="color: red" v-if="report.orderStatus == '未到诊' && healthDate[idx] < nowDate">已过期</span>
                            </li>
                        </ul>
                    </div>
                    <div class="item-link">
                        <a @click="orderStatus(report)">体检报告</a>
                    </div>
                </div>
            </div>
        </div>
    </div>

<script>
    function goBack() {
        window.history.back();
    }
    new Vue({
        el:"#app",
        data:{
            reports:[],
            nowDate:"",
            healthDate:[],
        },
        methods:{
            findAll(){
                var year = new Date().getFullYear();
                var month = (new Date().getMonth()) + 1;
                var day = new Date().getDate();
                this.nowDate = new Date(year + "-" + month + "-" + day);

                let token = localStorage.getItem("security_token");
                if (!token){
                    token = "";
                }
                axios({
                    url:"http://localhost:8081/report",
                    method:"GET",
                    headers:{
                        token:token
                    },
                }).then(resp=>{
                    let r = resp.data;
                    if (r.code == 200){
                        let r = resp.data;
                        if (r.data.length < 1){
                            alert("暂无体检报告")
                            location.href  = "health-index.html";
                        }
                        for (let i = 0;i < r.data.length;i++){
                            let a = new Date(r.data[i].healthDate);
                            this.healthDate[i] = a;
                        }

                        this.reports = r.data;
                    }else if (r.code == 401){
                        alert(r.message)
                        location.href = "health-login.html";
                    }else {
                        alert(r.message)
                    }
                })
            },
            orderStatus(report){
                if (report.orderStatus != "未到诊"){
                    location.href = "health-reportDetail.html?fileNumber=" + report.fileNumber;
                }else if (this.guoqi != null && this.guoqi != ""){
                    alert("已过期");
                }else {
                    alert("未到诊")
                }
            }
        },
        mounted(){
            this.findAll();
        }
    })
</script>
</body>